function decodingPerception(subjID, acqDate, toilimTime, foi, toi, baseline, lambda, badChannels, condition)
	%% Analysis script for the pilot of the decoding of perception paradigm.
	% Runs the complete analysis on the decoding of perception data, skipping the steps which are done (i.e. for which the output files already exist)
	% Mostly, this function uses Torque to run the underlying functions. Exceptions are artifact rejection, which requires user input, and plotting, which is messy on the Torque  mentats
	%
    % subjID: subject identifier
	% acqDate: date of acquisition in the format yyymmdd. This is needed to get the full name of the dataset, but is planned to become obsolete in later versions
	% toilimTime: toi for classification in the time domain, in the format[beginTime endTime]
	% foi: foi for classification in the frequency domain, in the format beginFreq:stepsize:endFreq
	% toi: toi for classification in the frequency domain, in the format beginTime:stepsize:endTime
	% baseline: baseline for plotting of the TFRs, in the format [beginBaseline endBaseline]
	% lambda: lambda parameter for the elastic net method
    % badChannels: optional. Cell array of bad channels that should be
    % removed from analysis. If all channels are good, an empty cell should
    % be specified.
	% condition: Optional. Specify 'lum'  for luminance corrected only
	% trials or 'lum_spat' for both luminance and spatial frequency
	% corrected trials. When no condition is specified, the default
	% triggercodes of 21-25 for faces to words are used. Note that this
	% parameter is planned to be replaced in a next version by
	% trigger-stimulus pairs.
	%
	% Main output are images, which are stored in subjectDir. The name of the images resemble the *.mat file in which the data for creating the image is stored.
	%
	% Note: at this moment the script expects the dataset in the subjectDir folder (see below). In a later version I plan to merge this with an md5 checksum bash script, which will probably also move the dataset to the right position.
	% Together with that adaptation, the acqDate parameter is planned to be removed.
	%
	% Still missing: classification on eyetracker and in source space
	
	
    clearvars -except subjID acqDate toilimTime foi toi baseline lambda badChannels condition
    close all;
	clc;
    
    className = {'face','scene', 'body','tool', 'word'};
   
    if ~exist('condition', 'var')
        condition = 'noCond';
    end
    
	
    dataDir = '~/data';
    
    grad = 'planar';

    subject = [];
    subject.subjID = subjID;
    subject.subjectDir = sprintf('%s/%s', dataDir, subject.subjID);
    
    subject.allChannels = ['all', badChannels];
    subject.MEGChannels = ['MEG', badChannels];
    subject.MRTChannels = ['MRT*', badChannels];

    if ~exist(subject.subjectDir, 'file')
         system(sprintf('mkdir %s', subject.subjectDir));
    end
    
    if ~exist([subject.subjectDir, '/', subject.subjID, '_', condition, '_toilimTime-', num2str(toilimTime(1)), '-', num2str(toilimTime(2)), '_foi-', num2str(min(foi)), '-', num2str(foi(2)-foi(1)), '-', num2str(max(foi)), '_toi-', num2str(min(toi)), '-', num2str(toi(2)-toi(1)), '-', num2str(max(toi)), '_baseline-', num2str(baseline(1)), '-', num2str(baseline(2)), '.mat'], 'file')
        save([subject.subjectDir, '/', subject.subjID, '_', condition, '_toilimTime-', num2str(toilimTime(1)), '-', num2str(toilimTime(2)), '_foi-', num2str(min(foi)), '-', num2str(foi(2)-foi(1)), '-', num2str(max(foi)), '_toi-', num2str(min(toi)), '-', num2str(toi(2)-toi(1)), '-', num2str(max(toi)), '_baseline-', num2str(baseline(1)), '-', num2str(baseline(2)), '.mat'], '-v7.3'); %save parameters and basic variables, so they can easily be accessed. NOTE: only save when the file does not exist yet: appending would overwrite the full subject struct including noWords witht he current state, which at the moment of saving has no noWords yet.
    end 

	% NOTE: can also be done by looking in the subjID folder in which the
    % copy/md5 script it will put it, in that way acqDate can be extracted
    % from there, as well as the corresponding MRI scan.
 
    subject.fullData = sprintf('%s/%s_1200hz_%s_01.ds', subject.subjectDir, subject.subjID, num2str(acqDate));
    subject.resampledData = sprintf('%s/decperc_%s_600hz_%s_01.ds', subject.subjectDir, subject.subjID, num2str(acqDate));
    subject.MRI = sprintf('%s/%s.mri', subject.subjectDir, subject.subjID); %final format not yet known, will likely be related to copy/md5 script, probably will also include T1 acquisition date
    
    %cd(qsubDir);
    
	%% Resampling

    if exist(subject.resampledData, 'dir')
        display(sprintf('Resampled dataset %s already exists. Skipping...', subject.resampledData));
    else
        %NOTE: cfg now corrects 60 Hz light net instead of 50Hz
        system(sprintf('/opt/ctf-5.4.0/bin/newDs -filter %s/1200to600Hz.cfg -resample 2 %s %s', dataDir, subject.fullData, subject.resampledData));
    end
	%% Data selection

	% select all non-response trials
	if exist([subject.subjectDir,'/',subjID, '_', condition, '_cfg_rejectArtifact.mat'], 'file');
        display(sprintf('Artifact rejected data for subject %s already exists. Skipping...', subject.subjID));
	else
%         if strcmp(subject.subjID, 'P01') %because P01 has different trigger codes
%             cfg = [];
%             cfg.dataset             = subject.resampledData;
%             cfg.trialdef.eventtype	= 'UPPT001';
%             cfg.trialfun            = 'trlfun_decperc';
%             cfg                     = ft_definetrial(cfg);
%             allTrials               = cfg.trl;
%          else
%             cfg = [];
%             cfg.datafile                = subject.resampledData;
%             cfg.trialdef.eventtype      = 'UPPT001';
%             cfg.trialdef.prestim        = 3; %2.5; %may want to timelock this to the stimulus-onset trigger, eventvalue 101:220
%             cfg.trialdef.poststim       = 1; %0; %NOTE: may want to use 3 pre and 1 post anyway, and later on select what you want to look at instead of having to preprocess all over again
%             cfg.trialdef.eventvalue     = 21:25; %trialcode
%             cfg                         = ft_definetrial(cfg);
%             allTrials                   = cfg.trl;
%         end
        
        cfg                     = [];
        cfg.dataset             = subject.resampledData;
        cfg.condition           = condition;
        cfg.trialdef.eventtype	= 'UPPT001';
        if strcmp(subject.subjID, 'P01')
            cfg.trialfun        = 'trlfun_decperc_P01';
        else
            cfg.trialfun        = 'trlfunDecodingPerception';
        end
        cfg_definetrial         = ft_definetrial(cfg);
        allTrials               = cfg_definetrial.trl;

        if strcmp(subject.subjID, 'P01')
            display(sprintf('Number of face trials is %i', size(find(allTrials(:,4) == 201), 1)));
            display(sprintf('Number of scene trials is %i', size(find(allTrials(:,4) == 202), 1)));
            display(sprintf('Number of body trials is %i', size(find(allTrials(:,4) == 203), 1)));
            display(sprintf('Number of tool trials is %i', size(find(allTrials(:,4) == 204), 1)));
            display(sprintf('Number of word trials is %i', size(find(allTrials(:,4) == 205), 1)));
            display(sprintf('\nTotal number of valid trials is %i', size(find(allTrials(:,4) == 201), 1) + size(find(allTrials(:,4) == 202), 1) + size(find(allTrials(:,4) == 203), 1) + size(find(allTrials(:,4) == 204), 1) + size(find(allTrials(:,4) == 205), 1)));

            if (size(find(allTrials(:,4) == 201), 1) + size(find(allTrials(:,4) == 202), 1) + size(find(allTrials(:,4) == 203), 1) + size(find(allTrials(:,4) == 204), 1) + size(find(allTrials(:,4) == 205), 1) ~= length(allTrials)) %error in division
                error('ERROR: Sum of all defined trials is not equal to the total number of trials.');
            end
            
            if isempty(find(allTrials(:,4) == 25, 1))
                subject.noWords = 0;
            else
                subject.noWords = 1;
            end
            
        else
            if strcmp(condition, 'noCond') || strcmp(condition, 'lum_spat') % trigger codes are 21-25
                display(sprintf('Number of face trials is %i', size(find(allTrials(:,4) == 21), 1)));
                display(sprintf('Number of scene trials is %i', size(find(allTrials(:,4) == 22), 1)));
                display(sprintf('Number of body trials is %i', size(find(allTrials(:,4) == 23), 1)));
                display(sprintf('Number of tool trials is %i', size(find(allTrials(:,4) == 24), 1)));
                display(sprintf('Number of word trials is %i', size(find(allTrials(:,4) == 25), 1)));
                display(sprintf('\nTotal number of valid trials is %i', size(find(allTrials(:,4) == 21), 1) + size(find(allTrials(:,4) == 22), 1) + size(find(allTrials(:,4) == 23), 1) + size(find(allTrials(:,4) == 24), 1) + size(find(allTrials(:,4) == 25), 1)));

                if (size(find(allTrials(:,4) == 21), 1) + size(find(allTrials(:,4) == 22), 1) + size(find(allTrials(:,4) == 23), 1) + size(find(allTrials(:,4) == 24), 1) + size(find(allTrials(:,4) == 25), 1) ~= length(allTrials)) %error in division
                    error('ERROR: Sum of all defined trials 1 is not equal to the total number of trials.');
                end

                if isempty(find(allTrials(:,4) == 25, 1))
                    subject.noWords = 1;
                else
                    subject.noWords = 0;
                end
            
            elseif strcmp(condition, 'lum')

                display(sprintf('Number of face trials is %i', size(find(allTrials(:,4) == 31), 1)));
                display(sprintf('Number of scene trials is %i', size(find(allTrials(:,4) == 32), 1)));
                display(sprintf('Number of body trials is %i', size(find(allTrials(:,4) == 33), 1)));
                display(sprintf('Number of tool trials is %i', size(find(allTrials(:,4) == 34), 1)));
                display(sprintf('Number of word trials is %i', size(find(allTrials(:,4) == 35), 1)));
                display(sprintf('\nTotal number of valid trials is %i', size(find(allTrials(:,4) == 31), 1) + size(find(allTrials(:,4) == 32), 1) + size(find(allTrials(:,4) == 33), 1) + size(find(allTrials(:,4) == 34), 1) + size(find(allTrials(:,4) == 35), 1)));

                if (size(find(allTrials(:,4) == 31), 1) + size(find(allTrials(:,4) == 32), 1) + size(find(allTrials(:,4) == 33), 1) + size(find(allTrials(:,4) == 34), 1) + size(find(allTrials(:,4) == 35), 1) ~= length(allTrials)) %error in division
                    error('ERROR: Sum of all defined trials is not equal to the total number of trials.');
                end

                if isempty(find(allTrials(:,4) == 35, 1))
                    subject.noWords = 1;
                else
                    subject.noWords = 0;
                end
                
            else
                error('ERROR: Unknown condition identifier. Please specify ''lum'' or ''lum_spat''');
            end
            
            save([subject.subjectDir, '/', subject.subjID, '_', condition, '_toilimTime-', num2str(toilimTime(1)), '-', num2str(toilimTime(2)), '_foi-', num2str(min(foi)), '-', num2str(foi(2)-foi(1)), '-', num2str(max(foi)), '_toi-', num2str(min(toi)), '-', num2str(toi(2)-toi(1)), '-', num2str(max(toi)), '_baseline-', num2str(baseline(1)), '-', num2str(baseline(2)), '.mat'], 'subject', '-append', '-v7.3'); %append the subject.noWords field
        end
        %% artifact rejection
        display(subject.noWords);
        artifactRejection(subject, allTrials, condition);
	end
    
    %% preprocessing 
  	if exist([subject.subjectDir,'/' subject.subjID, '_', condition, '_data.mat'], 'file')
        display(sprintf('Preprocessed data for subject %s already exists. Skipping...', subject.subjID));
    else
        qsubcellfun(@preproc, {subject}, {grad}, {condition}, 'memreq', 6*1024^3, 'timreq', 1000)
    end    
    %% sensor level classification in the time domain
    if ~exist('subject.noWords', 'var') %if the noWords var doesn't exist beacuse that step was already done and hence skipped
        load([subject.subjectDir, '/', subject.subjID, '_', condition, '_toilimTime-', num2str(toilimTime(1)), '-', num2str(toilimTime(2)), '_foi-', num2str(min(foi)), '-', num2str(foi(2)-foi(1)), '-', num2str(max(foi)), '_toi-', num2str(min(toi)), '-', num2str(toi(2)-toi(1)), '-', num2str(max(toi)), '_baseline-', num2str(baseline(1)), '-', num2str(baseline(2)), '.mat']);
    end
    
    subjList = {}; toilimTimeList = {}; class1List = {}; class2List = {}; condList = {}; lambdaList = {};
    startClass = 2;
    for i = 1:length(className) - 1 - subject.noWords
        for j = startClass:length(className) - subject.noWords
            if exist([subject.subjectDir, '/', subject.subjID, '_', condition, '_sensorLevel_', className{i},'-', className{j} '_toi_', num2str(toilimTime(1)), '-', num2str(toilimTime(2)), '.mat'], 'file')
                display(sprintf('Sensor level classification for subject %s, class %s vs %s, with toi ranging from %i to %i already exists. Skipping...', subject.subjID, className{i}, className{j}, toilimTime(1), toilimTime(2)))
            else
                subjList = [subjList, {subject}];
                toilimTimeList = [toilimTimeList, {toilimTime}];
                class1List = [class1List, {className{i}}];
                class2List = [class2List, {className{j}}];
                condList = [condList, {condition}];
                lambdaList = [lambdaList, {lambda}];
            end
        end
        startClass = startClass +1;
    end
 
    if ~isempty(subjList)
        qsubcellfun(@sensorLevelClassification, subjList, toilimTimeList, class1List, class2List, condList, lambdaList, 'memreq', 2*1024^3, 'timreq', 1000);
    end
    
    % plot data
    startClass = 2;
    for i = 1:length(className) - 1 - subject.noWords
        for j = startClass:length(className) - subject.noWords
            if exist([subject.subjectDir, '/', subject.subjID, '_', condition, '_sensorLevel_', className{i},'-', className{j}, '_toi_', num2str(toilimTime(1)), '-', num2str(toilimTime(2)),'.png'], 'file')
                display(sprintf('Sensor level classification of %s vs %s for subject %s already plotted. Skipping...', className{i}, className{j}, subject.subjID));
            else
                try
                    loadSucces = 0;
                    load([subject.subjectDir, '/', subject.subjID, '_', condition, '_sensorLevel_', className{i},'-', className{j}, '_toi_', num2str(toilimTime(1)), '-', num2str(toilimTime(2)), '.mat']);
                    loadSucces = 1;

                    % plot importance map
                    eval([subject.subjID, '_sensorLevel_', className{i},'_vs_', className{j}, '_fig = figure;']);
                    eval(['title(sprintf(''subject %s condition %s: %s vs %s; performance is %i'', subject.subjID, condition, className{i}, className{j}, tstat_', className{i},'_', className{j}, '.performance));']);
                    cfg             = [];
                    cfg.layout      = 'CTF275.lay';
                    %cfg.xlim         = [-3.2+(i/5) -2+(i/5)];
                    cfg.parameter   = 'model1';
                    cfg.colorbar    = 'yes';
                    cfg.marker      = 'no';
                    eval(['ft_topoplotER(cfg,tstat_', className{i}, '_', className{j}, ');']);
                    eval(['print(', subject.subjID, '_sensorLevel_', className{i},'_vs_', className{j}, '_fig, ', '''', subject.subjectDir, '/', subject.subjID, '_', condition, '_sensorLevel_', className{i},'-', className{j} '_toi_', num2str(toilimTime(1)), '-', num2str(toilimTime(2)),'.png'', ''-dpng'', ''-r90'')'] );
                catch
                    display(sprintf('Plotting of %s vs %s data for subject %s failed.', className{i}, className{j}, subject.subjID));
                    if loadSucces ==1
                        close(gcf);
                    end
                end
            end
        end
        startClass = startClass + 1;
    end
    
    clear tstat* ans; close all;
    %% classification in the frequency domain
    % frequency analysis (smoothing, phase?)
 
    % compute full power spectrum and power spectra per class
    eval(['toiBaseline = ', num2str(baseline(1)), ':', num2str(toi(2)-toi(1)), ':', num2str(max(toi)), ';']);  %toi = toi + baseline; for TFR's you want both the real toi and a baseline
       
    subjList = {}; toiList = {}; foiList = {}; classList = {}; condList = {};
    for i = 1:length(className) - subject.noWords
        if exist([subject.subjectDir, '/', subject.subjID, '_', condition, '_freqAnalysis_', className{i},'_foi_', num2str(min(foi)), '-', num2str(max(foi)), '-by-', num2str(foi(2)-foi(1)), '_toi_', num2str(min(toiBaseline)), '-', num2str(max(toiBaseline)), '-by-', num2str(toiBaseline(2)-toiBaseline(1)), '.mat'], 'file');
            display(sprintf('Frequency analysis for %s class of subject %s with toi = %i:%i:%i and foi = %i:%i:%i already exists. Skipping...', className{i}, subject.subjID, min(toiBaseline), toiBaseline(2)-toiBaseline(1), max(toiBaseline), min(foi), foi(2)-foi(1), max(foi)));
        else
            subjList = [subjList, {subject}];
            toiList = [toiList, {toiBaseline}];
            foiList = [foiList, {foi}];
            classList = [classList, {className{i}}];
            condList = [condList, {condition}];
        end
    end

    if ~isempty(subjList)
        qsubcellfun(@doFreqAnalysis, subjList, toiList, foiList, classList, condList, 'memreq', 30*1024^3, 'timreq', 4000);
    end
    
    % plot TFRs
    %NOTE: mem req > 10Gb, causing this to be very prone to failing
    for i = 1:length(className) - subject.noWords
        if exist([subject.subjectDir, '/', subject.subjID, '_', condition, '_freqAnalysis_', className{i},'_foi_', num2str(min(foi)), '-', num2str(max(foi)), '-by-', num2str(foi(2)-foi(1)), '_toi_', num2str(min(toiBaseline)), '-', num2str(max(toiBaseline)), '-by-', num2str(toiBaseline(2)-toiBaseline(1)),'.png'], 'file')
            display(sprintf('TFR of %s class for subject %s already plotted. Skipping...', className{i}, subject.subjID));
        else
            try
                loadSucces = 0;
                load([subject.subjectDir, '/', subject.subjID, '_', condition, '_freqAnalysis_', className{i},'_foi_', num2str(min(foi)), '-', num2str(max(foi)), '-by-', num2str(foi(2)-foi(1)), '_toi_', num2str(toiBaseline(1)), '-', num2str(max(toiBaseline)), '-by-', num2str(toiBaseline(2)-toiBaseline(1)), '.mat'])
                loadSucces = 1;

                % plot TFR
                eval([subject.subjID, 'data_freqAnalysis_', className{i}, '_fig = figure;']);
                cfg = [];
                cfg.parameter = 'powspctrm';
                cfg.baseline	= baseline;
                cfg.baselinetype= 'relative';
                cfg.zlim       = [ 0.5 1.5];
                cfg.xlim = [min(toiBaseline) max(toiBaseline)];
                cfg.showlabels = 'yes';
                %cfg.channel 	= 'MZP01';
                cfg.channel  = subject.MEGChannels;
                eval(['ft_singleplotTFR(cfg, data_freqAnalysis_', className{i}, ');']);
                drawnow;
                title(className{i});
                eval(['print(', subject.subjID, 'data_freqAnalysis_', className{i}, '_fig, ', '''',subject.subjectDir, '/', subject.subjID, '_', condition, '_freqAnalysis_', className{i},'_foi_', num2str(min(foi)), '-', num2str(max(foi)), '-by-', num2str(foi(2)-foi(1)), '_toi_', num2str(min(toiBaseline)), '-', num2str(max(toiBaseline)), '-by-', num2str(toiBaseline(2)-toiBaseline(1)),'.png'', ''-dpng'', ''-r90'')'] );
            catch
                display(sprintf('Plotting of TFR for category %s for subject %s failed', className{i}, subject.subjID));
                if loadSucces == 1
                    close(gcf);
                end
            end
        end
    end
    
    clear data_freqAnalysis* ans; close all
    %% Classification in frequency domain

    subjList = {}; toiList = {}; foiList = {}; lambdaList = {}; class1List = {}; class2List = {}; condList = {};
    startClass = 2;
    for i = 1:length(className) - 1 - subject.noWords
        for j = startClass:length(className) - subject.noWords
            if exist([subject.subjectDir, '/', subject.subjID, '_', condition, '_sensorLevelFreq_', className{i}, '-', className{j}, '_foi_', num2str(min(foi)), '-', num2str(max(foi)), '-by-', num2str(foi(2)-foi(1)), '_toi_', num2str(min(toi)), '-', num2str(max(toi)), '-by-', num2str(toi(2)-toi(1)), '_lambda_', num2str(lambda), '.mat'],'file')
                display(sprintf('Frequency classification for subject %s, class %s vs %s, with toi ranging from %i to %i already exists. Skipping...', subject.subjID, className{i}, className{j}, min(toi), max(toi)));
            else
                subjList = [subjList, {subject}];
                toiList = [toiList, {toi}];
                foiList = [foiList, {foi}];
                lambdaList = [lambdaList, {lambda}];
                class1List = [class1List, {className{i}}];
                class2List = [class2List, {className{j}}];
                condList = [condList, {condition}];
            end
        end
        startClass = startClass +1;
    end
    
    if ~isempty(subjList)
        qsubcellfun(@sensorLevelClassifyFrequency, subjList, toiList, foiList, lambdaList, class1List, class2List, condList, 'memreq', 15*1024^3, 'timreq', 5000);
    end
       
    % plot importance maps
	startClass = 2;
    
    for i = 1:size(className,2) - 1 - subject.noWords
        for j = startClass:size(className,2) - subject.noWords
            if exist([subject.subjectDir, '/', subject.subjID, '_', condition, '_sensorLevelFreq_', className{i}, '-', className{j}, '_foi_', num2str(min(foi)), '-', num2str(max(foi)), '-by-', num2str(foi(2)-foi(1)), '_toi_', num2str(min(toi)), '-', num2str(max(toi)), '-by-', num2str(toi(2)-toi(1)), '_lambda_', num2str(lambda), '.png'], 'file')
                display(sprintf('Frequency classification of %s vs %s for subject %s already plotted. Skipping...', className{i}, className{j}, subject.subjID));
            else
                try
                    loadSucces = 0;
                    load([subject.subjectDir, '/', subject.subjID, '_', condition, '_sensorLevelFreq_', className{i}, '-', className{j}, '_foi_', num2str(min(foi)), '-', num2str(max(foi)), '-by-', num2str(foi(2)-foi(1)), '_toi_', num2str(min(toi)), '-', num2str(max(toi)), '-by-', num2str(toi(2)-toi(1)), '_lambda_', num2str(lambda), '.mat']);
                    loadSucces = 1;

                    eval([subject.subjID, '_freqStat_', className{i}, '_', className{j}, '_fig = figure;']);
                    eval(['title(sprintf(''subject %s: %s vs %s; lambda is %i, performance is %i'', subject.subjID, className{i}, className{j}, lambda, freqStat_', className{i},'_', className{j}, '.performance));']);
                    cfg             = [];
                    cfg.layout      = 'CTF275.lay';
                    cfg.interactive = 'yes';
                    %cfg.xlim         = [-3.2+(i/5) -2+(i/5)];
                    cfg.parameter   = 'model1';
                    cfg.colorbar    = 'yes';
                    cfg.marker      = 'no';
                    eval(['ft_topoplotER(cfg,freqStat_', className{i}, '_', className{j},');']);
                    eval(['print(', subject.subjID, '_freqStat_', className{i}, '_', className{j}, '_fig, ', '''', subject.subjectDir, '/', subject.subjID, '_', condition, '_sensorLevelFreq_', className{i}, '-', className{j}, '_foi_', num2str(min(foi)), '-', num2str(max(foi)), '-by-', num2str(foi(2)-foi(1)), '_toi_', num2str(min(toi)), '-', num2str(max(toi)), '-by-', num2str(toi(2)-toi(1)), '_lambda_', num2str(lambda), '.png'', ''-dpng'', ''-r90'')'] );
                catch
                    display(sprintf('Plotting of %s vs %s data for subject %s failed.', className{i}, className{j}, subject.subjID));
                    if loadSucces ==1
                        close(gcf);
                    end
                end
            end
        end
        startClass = startClass + 1;    
    end
    clear freqStat* ans; close all;
    %% Sanity check: classify on eyetracker and EOG
    
    % for the ERP time window
    if exist([subject.subjectDir, '/', subject.subjID, '_', condition, '_eyetrackerClassification_toi_', num2str(min(toilimTime)), '-', num2str(max(toilimTime)), '.mat'], 'file')
        display(sprintf('Eyetracker data for subject %s already analysed for toi ranging from %i to %i. Skipping...', subject.subjID, min(toilimTime), max(toilimTime)));
    else
        eyetrackerClassification(subject, toilimTime, className, condition);
    end
    
    % for the sustained time window
    if exist([subject.subjectDir, '/', subject.subjID, '_', condition, '_eyetrackerClassification_toi_', num2str(min(toi)), '-', num2str(max(toi)), '.mat'], 'file')
        display(sprintf('Eyetracker data for subject %s already analysed for toi ranging from %i to %i. Skipping...', subject.subjID, min(toilimTime), max(toilimTime)));
    else
        eyetrackerClassification(subject, toi, className, condition);
    end
    %% Beamforming
    
    % WORK IN PROGRESS
    % classification on source level
    
    
    % classify on ICA components?

end
